

package Componentes.Validators;

import Configuraciones.Configuraciones;
import java.awt.Color;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JComponent;
import org.jdesktop.beansbinding.Validator;


public class MailValidator extends Validator<String>{
    private int min=0;
    private int max=0;
    private JComponent obj;
    boolean isValid=true;
    
    public MailValidator(){

    }

    @Override
    public Result validate(String val) {
        if(val.trim().length()>min && val.trim().length()<max){
            Pattern p= Pattern.compile(
                    "^[\\w\\-\\_]+(\\.[\\w\\-\\_]+)*@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$");
            Matcher m=p.matcher(val);
            isValid=isValid && m.find();
            
            if(!isValid){ 
                
                return new Result(null, " invalido  ");
            }
            
        }else{
            
            return new  Result(null, " fuera de Rango  ");
        }
        
        getObj().setBackground(Color.white);
        return null;
    
    }

   
    public int getMin() {
        return min;
    }

 
    public void setMin(int min) {
        this.min = min;
    }

  
    public int getMax() {
        return max;
    }

  
    public void setMax(int max) {
        this.max = max;
    }

  
    public JComponent getObj() {
        return obj;
    }

    public void setObj(JComponent obj) {
        this.obj = obj;
    }

}
